package com.kaishengit.web.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.kaishengit.entity.User;

public class QuanFilter extends AbstractFilter {

	@Override
	public void doFilter(ServletRequest req, ServletResponse resp,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest)req;
		HttpServletResponse response = (HttpServletResponse)resp;
		String uri = request.getRequestURI();
		uri = uri.substring(uri.lastIndexOf("/")+1);
		if ("".equals(uri)||"index.jsp".equals(uri)||"index.jspx".equals(uri)||"login.jspx".equals(uri)||uri.endsWith("jpg")) {
			chain.doFilter(request, response);
		} else {
			HttpSession session = request.getSession();
			User user = (User)session.getAttribute("user");
			if (user == null) {
				response.sendRedirect("index.jsp?code=10002");
			} else {
				chain.doFilter(request, response);
			}
		}
		
	}
}
